<?php
/**
 * Created by PhpStorm.
 * User: tianhuining
 * Date: 2022/1/2
 * Time: 下午6:02
 */

ini_set('display_errors', 1);
error_reporting(1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\wiki\Wiki as mWiki;
use Biz\service\wiki\SelectionLib;
use Biz\cache\wiki\SelectionLib as CacheSelectionLib;
use Doraemon\tools\Log;



// $wikiInfo =  mWiki::selectByWhere(['last_category_id[!]'=> 0 ,'channel_type' => mWiki::CHANNEL_TYPE_TAOBAO, 'LIMIT' => [0,2000]]);
$content =  file_get_contents("/home/adm_rsync_dir/selected_goods.txt");
$itemIds = explode("\n" , $content);
echo date("Y-m-d H:i:s" , time());
 if($itemIds && is_array($itemIds)){
     SelectionLib::setCateMap();
     while($itemIds){
         $sliceIds = array_slice($itemIds ,  0,40);
         updateItemPriceInfo($sliceIds);
         $itemIds = array_diff($itemIds , $sliceIds);
         var_dump(count($itemIds));
     }
 }

function InsertGoodsInfo($itemIds){
       $ItemsInfo = SelectionLib::getItemsInfoByIds($itemIds);
       if($ItemsInfo && is_array($ItemsInfo)){
           foreach ($ItemsInfo as $itemId => $ItemInfo){
               if($ItemInfo && is_array($ItemInfo)){
                   $cateInfo = SelectionLib::getCateInfo( $ItemInfo['cat_leaf_name'] , $itemId);
                   $ItemInfo = array_merge($ItemInfo , $cateInfo);
                   $wikiId =   SelectionLib::updateWikiInfo($itemId , $cateInfo);
                   $ItemInfo['wiki_id'] = $wikiId;
                   SelectionLib::updateItemInfo($itemId ,$ItemInfo,$wikiId);
                   //生成缓存数据
                   CacheSelectionLib::setGoodsPriceById($itemId , $ItemInfo['zk_final_price']);
                   //生成缓存数据
               }else{
                   var_dump($itemId);
                   Log::wiki_getTaoBaoByItemId_warning('获取不到信息:' .$itemId);
               }
           }
       }else{
           Log::wiki_getTaoBaoByItemId_warning('获取不到信息:' .implode(","  ,$itemIds));
       }
 }


 function updateItemPriceInfo($itemIds){
     $ItemsInfo = SelectionLib::getItemsInfoByIds($itemIds);
     if($ItemsInfo && is_array($ItemsInfo)){
         foreach ($ItemsInfo as $itemId => $ItemInfo){
             if($ItemInfo && is_array($ItemInfo)){
                 SelectionLib::updateItemInfo($itemId ,$ItemInfo);
                 //生成缓存数据
                 CacheSelectionLib::setGoodsPriceById($itemId , $ItemInfo['zk_final_price']);
                 //生成缓存数据
             }else{
                 var_dump($itemId);
                 Log::wiki_getTaoBaoPriceByItemId_warning('获取不到价格信息:' .$itemId);
             }
         }
     }else{
         Log::wiki_getTaoBaoPriceByItemId_warning('获取不到价格信息:' .implode(","  ,$itemIds));
     }
 }
echo date("Y-m-d H:i:s" , time());


